local jinmo = fk.CreateSkill{
  name = "xiaobai__jinmo"
}

jinmo:addEffect("active",{
  name = "xiaobai__jinmo",
  can_use = function (self, player)
    return #player:getCardIds("he")>0
  end,
  card_num = 1,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local mark = player:getMark("@$xiaobai__jinmo-cards")
    if Fk:getCardById(effect.cards[1]).color == Card.Red  then
      player.room:invalidateSkill(player,jinmo.name,"-phase")
      if type(mark) ~= "table" then room:throwCard(effect.cards,jinmo.name,player) return end
      for _, value in ipairs(mark) do
        room:obtainCard(player,room:getCardsFromPileByRule(".|.|.|.|.|.|"..value,1,"discardPile"),true,fk.ReasonPrey,player.id,jinmo.name)
      end
    end
    room:throwCard(effect.cards,jinmo.name,player)
  end
})

jinmo:addEffect(fk.AfterCardsMove, {
  mute = true,
  frequency = Skill.Compulsory,
  can_refresh = function (self, event, target, player, data)
    if (not player:hasSkill(self,true) )or (not player:hasSkill("xiaobai__jinmo",true)) then
      return false
    end
    for _, move in ipairs(data) do
      if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then 
        return true
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).color == Card.Red then
            player.room:setPlayerMark(player,"@$xiaobai__jinmo-cards",0)
          else
            player.room:addTableMark(player,"@$xiaobai__jinmo-cards",info.cardId)
          end
        end
      end
    end
  end
})

jinmo:addAcquireEffect(function (self, player)
  player.room.logic:getEventsByRule(GameEvent.MoveCards,1,function (e)
    for _, move in ipairs(e.data) do
      if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).color == Card.Red then
            return true
          else
            player.room:addTableMark(player,"@$xiaobai__jinmo-cards",info.cardId)
          end
        end
      end
    end
  end,Player.HistoryGame)
end)

jinmo:addLoseEffect(function (self, player)
  player.room:setPlayerMark(player,"@$xiaobai__jinmo-cards",0)
end)

Fk:loadTranslationTable{
  ["xiaobai__jinmo"] = "浸墨",
  ["@$xiaobai__jinmo-cards"] = "浸墨",
  ["#yinhan_prohibited"] = "浸墨",
  ["jinmo-give"] = "浸墨：你需将这些牌交给任意名角色",
  [":xiaobai__jinmo"] = "出牌阶段，你可以弃置一张牌，若之为红色，你获得进入弃牌堆的与上一张红色牌（单张进入的）之间的所有黑色牌（单张进入的），且此技能本阶段失效。",
  
  ["$xiaobai__jinmo1"] = "墨池飞鱼、笔锋族兔，成径丈之势。",
  ["$xiaobai__jinmo2"] = "笺麻素绢、石砚浮光，须臾落千言。",
}

return jinmo